# This script creates the data set for the robustness checks involving NIBRS.

library(tidyverse)
library(lubridate)

load("combined_dta_long_483.rdata")

dta = dta %>%
  filter(type != "arrest")


dta_offenders = read_csv("nibrs_data.csv")
dta = bind_rows(dta, dta_offenders)
dta = dta %>%
  select(-platformId, -months_rep_any, -...29)

offender_ids = seq(-sum(is.na(dta$id)), -1, by=1)
dta[is.na(dta$id),]$id = offender_ids
save(dta, file="../data/combined_dta_long_483_nibrs.rdata")

dta_single = dta %>%
  filter(ori9 == agency) %>%
  select(-agency, -d)
save(dta_single, file="../data/single_dta_nibrs.rdata")
